package com.ziyun.erp.web.api.materialCategoryControllerApi;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.netflix.discovery.converters.Auto;
import com.utility.JsonUtils;
import com.utility.New;
import com.ziyun.erp.modules.material.entity.MaterialCategoryEntity;
import com.ziyun.erp.modules.material.entity.MaterialEntity;
import com.ziyun.erp.modules.material.service.MaterialCategoryService;
import com.ziyun.erp.modules.material.service.MaterialService;
import com.ziyun.erp.web.modules.capital.controller.QueryPage;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.sys.entity.SysUserEntity;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


/**
 * 耗材分类表
 *
 * @author xqz
 * @email ...
 * @date 2018-11-27 10:52:35
 */
@RestController
@RequestMapping("port/material/materialcategory")
public class MaterialCategoryControllerApi {
    @Autowired
    private MaterialCategoryService materialCategoryService;

    @Autowired
    private MaterialService materialService;



    /**
     * 获取分类树信息
     */
    @RequestMapping("/getTree")
    public R getTree(@RequestBody Map paramBodyMap){
        return  materialCategoryService.getTree();
    }


    /**
     * 列表
     */
    @RequestMapping("/queryMaterialsList")
    public R queryMaterialsList(@RequestBody Map paramBodyMap) {
        String categoryId = JsonUtils.object2String(paramBodyMap.get("categoryId"));
        QueryPage<MaterialEntity> queryPage = new QueryPage<>();
        queryPage.setPage(new Page<MaterialEntity>());
        queryPage.setParams(New.hashMap());
        Map<String, Object> params = queryPage.getParams();
        params.put("categoryId",categoryId);
        materialService.queryMaterialsListPage(queryPage.getPage(), queryPage.getParams());
        return R.ok().put("page", queryPage.getPage());
    }
}
